<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>

    function deepClone(obj) {
      var newObj = obj instanceof Array ? [] : {};

      for (var i in obj) newObj[i] = typeof obj[i] === "object" ? deepClone(obj[i]) : obj[i];

      return newObj;
    }

    const a = { a: 1, b: { d: 123 }, g: [ 1,2,3, { a: 1 }, []] };
    const b = deepClone(a);

    b.b = [0, 7, 8, 9];

    console.log(a);
    console.log(b);
    

  </script>
</body>
</html>